export class Yuntai {
  constructor(scene) {
    this.scene = scene;
  }

  createScene() {
    this.machine();
    this.laser();
    return this.scene;
  }
  machine() {
    let green = new BABYLON.StandardMaterial("green", this.scene);
    green.diffuseColor = new BABYLON.Color3(0, 1, 0); //Green
    let red = new BABYLON.StandardMaterial("red", this.scene);
    red.diffuseColor = new BABYLON.Color3(1, 0, 0); //Green

    let yt = new BABYLON.Mesh.CreateBox("yuntai", 4, this.scene);
    yt.material = green;

    let top = new BABYLON.Mesh.CreateBox(
      "top",
      2,
      this.scene,
      false,
      BABYLON.Mesh.DEFAULTSIDE
    );
    top.material = red;
    top.parent = yt;
    top.position.z = 2;

    yt.isVisible = true;
    return yt;
  }
  
  laser() {
    //creates lines using the vector3 myPoints array
    let ps = [new BABYLON.Vector3(0, 0, 0), new BABYLON.Vector3(100, 0, 0)];
    let myLines = BABYLON.MeshBuilder.CreateLines("laser", {
      points: ps,
    });

    let blue = new BABYLON.StandardMaterial("blue", this.scene);
    blue.diffuseColor = new BABYLON.Color3(0, 0, 1); //Green
    myLines.material = blue;

    let gl = new BABYLON.GlowLayer("glow", this.scene);
    gl.intensity = 2;
    gl.addIncludedOnlyMesh("laser");

    // update some or all values in myPoints array
    // updates the existing instance of myLines by pointing the instance property to it
    // myLines = BABYLON.MeshBuilder.CreateLines("lines", {
    //   points: myArray,
    //   instance: myLines,
    // });
    return myLines;
  }

  add_ground() {
    let ground = BABYLON.Mesh.CreateGround("ground", 6, 6, 1, this.scene);
    let grass0 = new BABYLON.StandardMaterial("grass0", this.scene);
    grass0.diffuseTexture = new BABYLON.Texture(
      "/static/img/a.png",
      this.scene
    );
    ground.material = grass0;
  }
  add_camera() {
    var camera = new BABYLON.ArcRotateCamera(
      "Camera",
      0,
      0.8,
      100,
      BABYLON.Vector3.Zero(),
      this.scene
    );
    camera.attachControl(this.canvas, false);
    return camera;
  }
}
